from dataclasses import dataclass, field
from typing import List


@dataclass
class Config:
    media_type: str
    size: int
    digest: str

    @classmethod
    def from_dict(cls, data: dict) -> 'Config':
        return cls(data['mediaType'], data['size'], data['digest'])


@dataclass
class Layer:
    media_type: str
    size: int
    digest: str

    @classmethod
    def from_dict(cls, data: dict) -> 'Layer':
        return cls(data['mediaType'], data['size'], data['digest'])


@dataclass
class Manifest:
    schema_version: int
    media_type: str
    config: Config
    layers: List[Layer] = field(default_factory=list)

    @classmethod
    def from_dict(cls, data: dict) -> 'Manifest':
        config = Config.from_dict(data['config'])
        layers = [Layer.from_dict(layer_data) for layer_data in data['layers']]
        return cls(data['schemaVersion'], data['mediaType'], config, layers)
